﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using BTv2.Controls;

namespace BTv2.Model
{
    public class Sensor
    {
        public int ID { get; set; }
        public string IndustrialPCID { get; set; }
        public string Name { get; set; }
        public bool Status { get; set; }
        public string Type { get; set; }
        public string MUnit { get; set; }
        public double MinValue { get; set; }
        public double MaxValue { get; set; }
        public double X { get; set; }
        public double Y { get; set; }
        public double Z { get; set; }

        public SensorData DataSet { get; set; }

        public async Task<DataPoint> GetCurrentValue()
        {
            double val = await IndustrialPCController.GetInstance().GetSensorValue(this.ID);
            DateTime now = DateTime.Now;
            if (DataSet == null)
            {
                DataSet = new SensorData();
                DataSet.EndTime = now;
                DataSet.StartTime = now;
                DataSet.Measurments.Add(new DataPoint() {Value=val, TimeStamp = now});
            }
            DataSet.EndTime = now;
            DataSet.Measurments.Add(new DataPoint() {Value = val, TimeStamp  =now});
            return DataSet.Measurments.Last();
        }
    }
}
